<%@page import="net.vinote.smart.platform.service.dw.html.UIEvent"%>
<%@page import="net.vinote.smart.platform.service.awe.layout.easyui.Button"%>
<%@page import="net.vinote.smart.platform.comm.PlatformConst.TreeProperty"%>
<%@page import="net.vinote.smart.platform.comm.StringFunction"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!--机构树图列表 -->
<%@include file="/comm/tree_begin.jsp"%>
<%
	String treeCode=request.getParameter("treeNo");
	boolean isMulti="true".equals(request.getParameter("isMulti"));//是否多选
	String callback=request.getParameter("callback");//回调函数
	String[] returnField=StringFunction.nullToBlank(request.getParameter("returnField")).split(",");
	tree = treeUI.getTreeBySQLCode(treeCode,isMulti?TreeProperty.SHOW_CHECKBOX:TreeProperty.DEFAULT);
	Button linkBtn = new Button(Button.BUTTON_TYPE_LINK);
	linkBtn.addContent("确定");
	linkBtn.addEvent(UIEvent.ON_CLICK, "doSure();");
	out.print(linkBtn.getHtml());
	linkBtn.setContent("清空");
	linkBtn.addEvent(UIEvent.ON_CLICK, "doClear()");
	out.print(linkBtn.getHtml());
%>
<div style="padding: 1px 0px;"></div>
<script>
	$(function() {
		$('#<%=treeCode%>').tree(
			{
				onDblClick: function(node) {
					<!--仅处理叶节点的双击事件-->
					if($(this).tree('isLeaf',node.target)){
						doSure();
					}
				}
			});
	});
	
function doSure(){
	var ids = [];
	var nodes=[];
	<%if(isMulti){%>
		nodes = $('#<%=treeCode%>').tree('getChecked');
	<%}else{%>
		nodes.push($('#<%=treeCode%>').tree('getSelected'));
	<%}%>
	for ( var i = 0; i < nodes.length; i++) {
		var returnObj={};
	<%
	for(int i=0;i<returnField.length;i++){
	%>
		returnObj['<%=returnField[i]%>']=nodes[i].attributes.<%=returnField[i].toUpperCase()%>
	<%}
	if(isMulti){
	%>
		ids.push(returnObj);
	<%}else{
	%>
		ids=returnObj;
	<%}%>
	}
	<%
	if(callback!=null){
	%>
		parent.<%=callback%>(ids);
	<%
	}
	%>
}
function doClear(){
	<%
	if(callback!=null){
		%>
		parent.<%=callback%>("_CLEAR_");
		<%
	}
%>
}

</script>
<%@include file="/comm/tree_end.jsp"%>
